package fr.toto.menuitem;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.nio.file.Path;

import javax.swing.JMenuItem;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.LocalizedMessage;

import com.kokotchy.betaSeriesAPI.model.Episode;

import fr.toto.constantes.Constantes;
import fr.toto.files.AccesFile;

public class OpenDirMenuItem extends JMenuItem implements Constantes {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4280206959179628646L;
	Episode ep = null;
	private static final Logger logger = LogManager
			.getLogger(OpenDirMenuItem.class);

	public OpenDirMenuItem(Episode e) {
		super(MESSAGES.getString("OpenDirMI"));
		this.ep = e;
		if (ep.isDownloaded()) {
			this.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					Path file = AccesFile.Find(ep);
					logger.info(new LocalizedMessage(DEBUGMSG,
							"fr.toto.menuitem.OpenDirMenuItem", file
									.getParent()));
					AccesFile.Open(file.getParent());
				}
			});
		} else {
			this.setEnabled(false);
		}
	}
}
